Skip to content

Replace findNodeHandle with reading _componentViewTag#6720

Merged
piaskowyk merged 2 commits intosoftware-mansion:mainfrom
gaearon:rm-findnodehandle
Nov 22, 2024
Merged

Replace findNodeHandle with reading _componentViewTag#6720
piaskowyk merged 2 commits intosoftware-mansion:mainfrom
gaearon:rm-findnodehandle

Conversation

@gaearon
Copy link
Contributor

@gaearon gaearon commented Nov 18, 2024

Summary

Partially addresses #6719.

This is better because it doesn't enter the traversal codepath inside React. The findNodeHandle calculation inside the Animated.View itself is not so bad because it's short circuited inside for native refs (at least with View). Whereas passing a class instance like here always triggers the slower path in React. Regardless, it's already computed so why compute again?

Test plan

I've added console logs in our app to verify whether animatedComponent._componentViewTag === findNodeHandle(animatedComponent) and it always turned out true in the cases I hit.

Not sure if there any cases where those could be different.

@tjzel
Copy link
Collaborator

tjzel commented Nov 18, 2024

I recall there was an issue that if a component doesn't have its own native representation (it wraps a View for example) then we need to re-obtain the tag in some cases (when the underlying View changes). Not sure if it applies here however.

@piaskowyk piaskowyk self-requested a review November 20, 2024 16:05
Copy link
Member

@piaskowyk piaskowyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate that you reported the issue and submitted a PR! Thanks for your time 🙏. I wanted to address other areas where we use the findNode handler, so I've created another PR that builds upon yours - #6736

@piaskowyk piaskowyk added this pull request to the merge queue Nov 22, 2024
Merged via the queue into software-mansion:main with commit e6ef338 Nov 22, 2024
@gaearon gaearon deleted the rm-findnodehandle branch November 22, 2024 14:21
tjzel pushed a commit that referenced this pull request Dec 13, 2024
## Summary

Partially addresses
#6719.

This is better because it doesn't enter the traversal codepath inside
React. The `findNodeHandle` calculation inside the `Animated.View`
itself is not so bad because it's short circuited inside for native refs
(at least with `View`). Whereas passing a class instance like here
always triggers the slower path in React. Regardless, it's already
computed so why compute again?

## Test plan

I've added console logs in our app to verify whether
`animatedComponent._componentViewTag ===
findNodeHandle(animatedComponent)` and it always turned out true in the
cases I hit.

Not sure if there any cases where those could be different.

Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
tjzel pushed a commit that referenced this pull request Dec 13, 2024
## Summary

Partially addresses
#6719.

This is better because it doesn't enter the traversal codepath inside
React. The `findNodeHandle` calculation inside the `Animated.View`
itself is not so bad because it's short circuited inside for native refs
(at least with `View`). Whereas passing a class instance like here
always triggers the slower path in React. Regardless, it's already
computed so why compute again?

## Test plan

I've added console logs in our app to verify whether
`animatedComponent._componentViewTag ===
findNodeHandle(animatedComponent)` and it always turned out true in the
cases I hit.

Not sure if there any cases where those could be different.

Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
tjzel pushed a commit that referenced this pull request Dec 13, 2024
## Summary

Partially addresses
#6719.

This is better because it doesn't enter the traversal codepath inside
React. The `findNodeHandle` calculation inside the `Animated.View`
itself is not so bad because it's short circuited inside for native refs
(at least with `View`). Whereas passing a class instance like here
always triggers the slower path in React. Regardless, it's already
computed so why compute again?

## Test plan

I've added console logs in our app to verify whether
`animatedComponent._componentViewTag ===
findNodeHandle(animatedComponent)` and it always turned out true in the
cases I hit.

Not sure if there any cases where those could be different.

Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
r0h0gg6 pushed a commit to r0h0gg6/react-native-reanimated that referenced this pull request Jul 28, 2025
…on#6720)

## Summary

Partially addresses
software-mansion#6719.

This is better because it doesn't enter the traversal codepath inside
React. The `findNodeHandle` calculation inside the `Animated.View`
itself is not so bad because it's short circuited inside for native refs
(at least with `View`). Whereas passing a class instance like here
always triggers the slower path in React. Regardless, it's already
computed so why compute again?

## Test plan

I've added console logs in our app to verify whether
`animatedComponent._componentViewTag ===
findNodeHandle(animatedComponent)` and it always turned out true in the
cases I hit.

Not sure if there any cases where those could be different.

Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants